/*
 * lrs_formater.cpp
 *
 *  Created on: Nov 5, 2012
 *      Author: m
 */

#include <memory>
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <sstream>

std::string outfileName;
std::string infileName;

void invalid_args()
{
    std::cerr << "Argumentos inválidos. "                                                 << std::endl
            << "Uso: lrs_formater infile outfile"                                         << std::endl
            << "Descripción: Formatea un archio de texto a registros de nodo hoja."       << std::endl
            << "\t el formato de los registros es: key(string) relPos(int) reserved(int)" << std::endl
            << "\t cada campo separado por espacios."                                     << std::endl;

    exit( 1 );
}

void parse_args( int argc, char* argv[] )
{
    infileName = argv[1];
    outfileName = argv[2];
}

int main( int argc, char* argv[] )
{
    std::ifstream infile;
    std::ofstream outfile;
    std::string stringBuffer;
    size_t lineCounter;
    int reserved;

    if ( argc != 3 )
        invalid_args();

    parse_args( argc, argv );

    infile.open( infileName );
    outfile.open( outfileName, std::ios_base::trunc );

    lineCounter = 0;
    reserved = 100;

    while( getline( infile, stringBuffer ) )
    {
        outfile << stringBuffer << " "
                << lineCounter  << " "
                << reserved     << std::endl;

        lineCounter++;
        reserved++;
    }

    infile.close();
    outfile.close();

    return 0;
}
